SET NOCOUNT ON
GO
USE [mydms]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UploadedDocument_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UploadedDocument_Insert]
GO
CREATE PROCEDURE [dbo].[TG_UploadedDocument_Insert]
	@Document_Code int output,
	@Document_Name varchar(50) = null ,
	@Document_Desc varchar(50) = null ,
	@File_Path varchar(50) = null ,
	@Is_Active bit = null ,
	@Creation_Date datetime = null ,
	@Updation_Date datetime = null 

AS

INSERT [dbo].[UploadedDocument]
(
	[Document_Name],
	[Document_Desc],
	[File_Path],
	[Is_Active],
	[Creation_Date],
	[Updation_Date]

)
VALUES
(
	@Document_Name,
	@Document_Desc,
	@File_Path,
	@Is_Active,
	@Creation_Date,
	@Updation_Date

)
	SELECT @Document_Code=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UploadedDocument_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UploadedDocument_Update]
GO
CREATE PROCEDURE [dbo].[TG_UploadedDocument_Update]
	@Document_Code int,
	@Document_Name varchar(50) = null,
	@Document_Desc varchar(50) = null,
	@File_Path varchar(50) = null,
	@Is_Active bit = null,
	@Creation_Date datetime = null,
	@Updation_Date datetime = null

AS

UPDATE [dbo].[UploadedDocument]
SET
	[Document_Name] = @Document_Name,
	[Document_Desc] = @Document_Desc,
	[File_Path] = @File_Path,
	[Is_Active] = @Is_Active,
	[Creation_Date] = @Creation_Date,
	[Updation_Date] = @Updation_Date
 WHERE 
	[Document_Code] = @Document_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UploadedDocument_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UploadedDocument_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_UploadedDocument_SelectByPrimaryKey]
	@Document_Code int
AS

	SELECT 
		[Document_Code], [Document_Name], [Document_Desc], [File_Path], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[UploadedDocument]
	WHERE 
			[Document_Code] = @Document_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UploadedDocument_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UploadedDocument_SelectAll]
GO
CREATE PROCEDURE [dbo].[TG_UploadedDocument_SelectAll]
AS

	SELECT 
		[Document_Code], [Document_Name], [Document_Desc], [File_Path], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[UploadedDocument]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UploadedDocument_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UploadedDocument_SelectByField]
GO
CREATE PROCEDURE [dbo].[TG_UploadedDocument_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [Document_Code], [Document_Name], [Document_Desc], [File_Path], [Is_Active], [Creation_Date], [Updation_Date] FROM [dbo].[UploadedDocument] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UploadedDocument_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UploadedDocument_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_UploadedDocument_DeleteByPrimaryKey]
	@Document_Code int
AS

DELETE FROM [dbo].[UploadedDocument]
 WHERE 
	[Document_Code] = @Document_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UploadedDocument_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UploadedDocument_DeleteByField]
GO
CREATE PROCEDURE [dbo].[TG_UploadedDocument_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[UploadedDocument] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserFolder_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserFolder_Insert]
GO
CREATE PROCEDURE [dbo].[TG_UserFolder_Insert]
	@Folder_Code int output,
	@Folder_Name varchar(50) = null ,
	@Folder_Path varchar(50) = null ,
	@Is_Active bit = null ,
	@Creation_Date datetime = null ,
	@Updation_Date datetime = null 

AS

INSERT [dbo].[UserFolder]
(
	[Folder_Name],
	[Folder_Path],
	[Is_Active],
	[Creation_Date],
	[Updation_Date]

)
VALUES
(
	@Folder_Name,
	@Folder_Path,
	@Is_Active,
	@Creation_Date,
	@Updation_Date

)
	SELECT @Folder_Code=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserFolder_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserFolder_Update]
GO
CREATE PROCEDURE [dbo].[TG_UserFolder_Update]
	@Folder_Code int,
	@Folder_Name varchar(50) = null,
	@Folder_Path varchar(50) = null,
	@Is_Active bit = null,
	@Creation_Date datetime = null,
	@Updation_Date datetime = null

AS

UPDATE [dbo].[UserFolder]
SET
	[Folder_Name] = @Folder_Name,
	[Folder_Path] = @Folder_Path,
	[Is_Active] = @Is_Active,
	[Creation_Date] = @Creation_Date,
	[Updation_Date] = @Updation_Date
 WHERE 
	[Folder_Code] = @Folder_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserFolder_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserFolder_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_UserFolder_SelectByPrimaryKey]
	@Folder_Code int
AS

	SELECT 
		[Folder_Code], [Folder_Name], [Folder_Path], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[UserFolder]
	WHERE 
			[Folder_Code] = @Folder_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserFolder_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserFolder_SelectAll]
GO
CREATE PROCEDURE [dbo].[TG_UserFolder_SelectAll]
AS

	SELECT 
		[Folder_Code], [Folder_Name], [Folder_Path], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[UserFolder]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserFolder_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserFolder_SelectByField]
GO
CREATE PROCEDURE [dbo].[TG_UserFolder_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [Folder_Code], [Folder_Name], [Folder_Path], [Is_Active], [Creation_Date], [Updation_Date] FROM [dbo].[UserFolder] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserFolder_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserFolder_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_UserFolder_DeleteByPrimaryKey]
	@Folder_Code int
AS

DELETE FROM [dbo].[UserFolder]
 WHERE 
	[Folder_Code] = @Folder_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserFolder_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserFolder_DeleteByField]
GO
CREATE PROCEDURE [dbo].[TG_UserFolder_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[UserFolder] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Department_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Department_Insert]
GO
CREATE PROCEDURE [dbo].[TG_Department_Insert]
	@Department_Code int output,
	@Department_Name varchar(50) = null ,
	@Location varchar(100) = null ,
	@Address varchar(100) = null ,
	@Is_Active bit = null ,
	@Creation_Date datetime = null ,
	@Updation_Date datetime = null 

AS

INSERT [dbo].[Department]
(
	[Department_Name],
	[Location],
	[Address],
	[Is_Active],
	[Creation_Date],
	[Updation_Date]

)
VALUES
(
	@Department_Name,
	@Location,
	@Address,
	@Is_Active,
	@Creation_Date,
	@Updation_Date

)
	SELECT @Department_Code=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Department_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Department_Update]
GO
CREATE PROCEDURE [dbo].[TG_Department_Update]
	@Department_Code int,
	@Department_Name varchar(50) = null,
	@Location varchar(100) = null,
	@Address varchar(100) = null,
	@Is_Active bit = null,
	@Creation_Date datetime = null,
	@Updation_Date datetime = null

AS

UPDATE [dbo].[Department]
SET
	[Department_Name] = @Department_Name,
	[Location] = @Location,
	[Address] = @Address,
	[Is_Active] = @Is_Active,
	[Creation_Date] = @Creation_Date,
	[Updation_Date] = @Updation_Date
 WHERE 
	[Department_Code] = @Department_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Department_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Department_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_Department_SelectByPrimaryKey]
	@Department_Code int
AS

	SELECT 
		[Department_Code], [Department_Name], [Location], [Address], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[Department]
	WHERE 
			[Department_Code] = @Department_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Department_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Department_SelectAll]
GO
CREATE PROCEDURE [dbo].[TG_Department_SelectAll]
AS

	SELECT 
		[Department_Code], [Department_Name], [Location], [Address], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[Department]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Department_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Department_SelectByField]
GO
CREATE PROCEDURE [dbo].[TG_Department_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [Department_Code], [Department_Name], [Location], [Address], [Is_Active], [Creation_Date], [Updation_Date] FROM [dbo].[Department] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Department_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Department_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_Department_DeleteByPrimaryKey]
	@Department_Code int
AS

DELETE FROM [dbo].[Department]
 WHERE 
	[Department_Code] = @Department_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Department_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Department_DeleteByField]
GO
CREATE PROCEDURE [dbo].[TG_Department_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Department] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_JobDescription_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_JobDescription_Insert]
GO
CREATE PROCEDURE [dbo].[TG_JobDescription_Insert]
	@JD_Code int output,
	@JD_Name varchar(50) = null ,
	@Job_Description varchar(100) = null ,
	@Is_Active bit = null ,
	@Creation_Date datetime = null ,
	@Updation_Date datetime = null 

AS

INSERT [dbo].[JobDescription]
(
	[JD_Name],
	[Job_Description],
	[Is_Active],
	[Creation_Date],
	[Updation_Date]

)
VALUES
(
	@JD_Name,
	@Job_Description,
	@Is_Active,
	@Creation_Date,
	@Updation_Date

)
	SELECT @JD_Code=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_JobDescription_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_JobDescription_Update]
GO
CREATE PROCEDURE [dbo].[TG_JobDescription_Update]
	@JD_Code int,
	@JD_Name varchar(50) = null,
	@Job_Description varchar(100) = null,
	@Is_Active bit = null,
	@Creation_Date datetime = null,
	@Updation_Date datetime = null

AS

UPDATE [dbo].[JobDescription]
SET
	[JD_Name] = @JD_Name,
	[Job_Description] = @Job_Description,
	[Is_Active] = @Is_Active,
	[Creation_Date] = @Creation_Date,
	[Updation_Date] = @Updation_Date
 WHERE 
	[JD_Code] = @JD_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_JobDescription_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_JobDescription_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_JobDescription_SelectByPrimaryKey]
	@JD_Code int
AS

	SELECT 
		[JD_Code], [JD_Name], [Job_Description], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[JobDescription]
	WHERE 
			[JD_Code] = @JD_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_JobDescription_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_JobDescription_SelectAll]
GO
CREATE PROCEDURE [dbo].[TG_JobDescription_SelectAll]
AS

	SELECT 
		[JD_Code], [JD_Name], [Job_Description], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[JobDescription]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_JobDescription_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_JobDescription_SelectByField]
GO
CREATE PROCEDURE [dbo].[TG_JobDescription_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [JD_Code], [JD_Name], [Job_Description], [Is_Active], [Creation_Date], [Updation_Date] FROM [dbo].[JobDescription] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_JobDescription_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_JobDescription_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_JobDescription_DeleteByPrimaryKey]
	@JD_Code int
AS

DELETE FROM [dbo].[JobDescription]
 WHERE 
	[JD_Code] = @JD_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_JobDescription_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_JobDescription_DeleteByField]
GO
CREATE PROCEDURE [dbo].[TG_JobDescription_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[JobDescription] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Office_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Office_Insert]
GO
CREATE PROCEDURE [dbo].[TG_Office_Insert]
	@Office_Code int output,
	@Office_Name varchar(50) = null ,
	@Office_Logo varchar(50) = null ,
	@Office_Slogan varchar(50) = null ,
	@Street_Address varchar(50) = null ,
	@City varchar(50) = null ,
	@Country varchar(50) = null ,
	@ZIP_Code varchar(50) = null ,
	@Account_Email varchar(50) = null ,
	@Account_Password varchar(50) = null ,
	@Is_Active bit = null ,
	@Creation_Date datetime = null ,
	@Updation_Date datetime = null 

AS

INSERT [dbo].[Office]
(
	[Office_Name],
	[Office_Logo],
	[Office_Slogan],
	[Street_Address],
	[City],
	[Country],
	[ZIP_Code],
	[Account_Email],
	[Account_Password],
	[Is_Active],
	[Creation_Date],
	[Updation_Date]

)
VALUES
(
	@Office_Name,
	@Office_Logo,
	@Office_Slogan,
	@Street_Address,
	@City,
	@Country,
	@ZIP_Code,
	@Account_Email,
	@Account_Password,
	@Is_Active,
	@Creation_Date,
	@Updation_Date

)
	SELECT @Office_Code=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Office_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Office_Update]
GO
CREATE PROCEDURE [dbo].[TG_Office_Update]
	@Office_Code int,
	@Office_Name varchar(50) = null,
	@Office_Logo varchar(50) = null,
	@Office_Slogan varchar(50) = null,
	@Street_Address varchar(50) = null,
	@City varchar(50) = null,
	@Country varchar(50) = null,
	@ZIP_Code varchar(50) = null,
	@Account_Email varchar(50) = null,
	@Account_Password varchar(50) = null,
	@Is_Active bit = null,
	@Creation_Date datetime = null,
	@Updation_Date datetime = null

AS

UPDATE [dbo].[Office]
SET
	[Office_Name] = @Office_Name,
	[Office_Logo] = @Office_Logo,
	[Office_Slogan] = @Office_Slogan,
	[Street_Address] = @Street_Address,
	[City] = @City,
	[Country] = @Country,
	[ZIP_Code] = @ZIP_Code,
	[Account_Email] = @Account_Email,
	[Account_Password] = @Account_Password,
	[Is_Active] = @Is_Active,
	[Creation_Date] = @Creation_Date,
	[Updation_Date] = @Updation_Date
 WHERE 
	[Office_Code] = @Office_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Office_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Office_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_Office_SelectByPrimaryKey]
	@Office_Code int
AS

	SELECT 
		[Office_Code], [Office_Name], [Office_Logo], [Office_Slogan], [Street_Address], [City], [Country], [ZIP_Code], [Account_Email], [Account_Password], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[Office]
	WHERE 
			[Office_Code] = @Office_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Office_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Office_SelectAll]
GO
CREATE PROCEDURE [dbo].[TG_Office_SelectAll]
AS

	SELECT 
		[Office_Code], [Office_Name], [Office_Logo], [Office_Slogan], [Street_Address], [City], [Country], [ZIP_Code], [Account_Email], [Account_Password], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[Office]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Office_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Office_SelectByField]
GO
CREATE PROCEDURE [dbo].[TG_Office_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [Office_Code], [Office_Name], [Office_Logo], [Office_Slogan], [Street_Address], [City], [Country], [ZIP_Code], [Account_Email], [Account_Password], [Is_Active], [Creation_Date], [Updation_Date] FROM [dbo].[Office] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Office_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Office_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_Office_DeleteByPrimaryKey]
	@Office_Code int
AS

DELETE FROM [dbo].[Office]
 WHERE 
	[Office_Code] = @Office_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_Office_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_Office_DeleteByField]
GO
CREATE PROCEDURE [dbo].[TG_Office_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[Office] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserInfo_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserInfo_Insert]
GO
CREATE PROCEDURE [dbo].[TG_UserInfo_Insert]
	@User_Code int output,
	@User_Name varchar(20) = null ,
	@User_Password varchar(50) = null ,
	@FirstName varchar(50) = null ,
	@LastName varchar(50) = null ,
	@Email_Address varchar(100) = null ,
	@Sex varchar(10) = null ,
	@About_Me varchar(500) = null ,
	@Activities varchar(500) = null ,
	@Interests varchar(500) = null ,
	@Street_Address varchar(500) = null ,
	@Online_Status varchar(10) = null ,
	@TimeZone_Code int = null ,
	@JD_Code int = null ,
	@Department_Code int = null ,
	@Is_Approved bit = null ,
	@Approved_By int = null ,
	@Is_Verified bit = null ,
	@Is_Active bit = null ,
	@Creation_Date datetime = null ,
	@Updation_Date datetime = null 

AS

INSERT [dbo].[UserInfo]
(
	[User_Name],
	[User_Password],
	[FirstName],
	[LastName],
	[Email_Address],
	[Sex],
	[About_Me],
	[Activities],
	[Interests],
	[Street_Address],
	[Online_Status],
	[TimeZone_Code],
	[JD_Code],
	[Department_Code],
	[Is_Approved],
	[Approved_By],
	[Is_Verified],
	[Is_Active],
	[Creation_Date],
	[Updation_Date]

)
VALUES
(
	@User_Name,
	@User_Password,
	@FirstName,
	@LastName,
	@Email_Address,
	@Sex,
	@About_Me,
	@Activities,
	@Interests,
	@Street_Address,
	@Online_Status,
	@TimeZone_Code,
	@JD_Code,
	@Department_Code,
	@Is_Approved,
	@Approved_By,
	@Is_Verified,
	@Is_Active,
	@Creation_Date,
	@Updation_Date

)
	SELECT @User_Code=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserInfo_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserInfo_Update]
GO
CREATE PROCEDURE [dbo].[TG_UserInfo_Update]
	@User_Code int,
	@User_Name varchar(20) = null,
	@User_Password varchar(50) = null,
	@FirstName varchar(50) = null,
	@LastName varchar(50) = null,
	@Email_Address varchar(100) = null,
	@Sex varchar(10) = null,
	@About_Me varchar(500) = null,
	@Activities varchar(500) = null,
	@Interests varchar(500) = null,
	@Street_Address varchar(500) = null,
	@Online_Status varchar(10) = null,
	@TimeZone_Code int = null,
	@JD_Code int = null,
	@Department_Code int = null,
	@Is_Approved bit = null,
	@Approved_By int = null,
	@Is_Verified bit = null,
	@Is_Active bit = null,
	@Creation_Date datetime = null,
	@Updation_Date datetime = null

AS

UPDATE [dbo].[UserInfo]
SET
	[User_Name] = @User_Name,
	[User_Password] = @User_Password,
	[FirstName] = @FirstName,
	[LastName] = @LastName,
	[Email_Address] = @Email_Address,
	[Sex] = @Sex,
	[About_Me] = @About_Me,
	[Activities] = @Activities,
	[Interests] = @Interests,
	[Street_Address] = @Street_Address,
	[Online_Status] = @Online_Status,
	[TimeZone_Code] = @TimeZone_Code,
	[JD_Code] = @JD_Code,
	[Department_Code] = @Department_Code,
	[Is_Approved] = @Is_Approved,
	[Approved_By] = @Approved_By,
	[Is_Verified] = @Is_Verified,
	[Is_Active] = @Is_Active,
	[Creation_Date] = @Creation_Date,
	[Updation_Date] = @Updation_Date
 WHERE 
	[User_Code] = @User_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserInfo_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserInfo_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_UserInfo_SelectByPrimaryKey]
	@User_Code int
AS

	SELECT 
		[User_Code], [User_Name], [User_Password], [FirstName], [LastName], [Email_Address], [Sex], [About_Me], [Activities], [Interests], [Street_Address], [Online_Status], [TimeZone_Code], [JD_Code], [Department_Code], [Is_Approved], [Approved_By], [Is_Verified], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[UserInfo]
	WHERE 
			[User_Code] = @User_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserInfo_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserInfo_SelectAll]
GO
CREATE PROCEDURE [dbo].[TG_UserInfo_SelectAll]
AS

	SELECT 
		[User_Code], [User_Name], [User_Password], [FirstName], [LastName], [Email_Address], [Sex], [About_Me], [Activities], [Interests], [Street_Address], [Online_Status], [TimeZone_Code], [JD_Code], [Department_Code], [Is_Approved], [Approved_By], [Is_Verified], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[UserInfo]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserInfo_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserInfo_SelectByField]
GO
CREATE PROCEDURE [dbo].[TG_UserInfo_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [User_Code], [User_Name], [User_Password], [FirstName], [LastName], [Email_Address], [Sex], [About_Me], [Activities], [Interests], [Street_Address], [Online_Status], [TimeZone_Code], [JD_Code], [Department_Code], [Is_Approved], [Approved_By], [Is_Verified], [Is_Active], [Creation_Date], [Updation_Date] FROM [dbo].[UserInfo] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserInfo_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserInfo_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_UserInfo_DeleteByPrimaryKey]
	@User_Code int
AS

DELETE FROM [dbo].[UserInfo]
 WHERE 
	[User_Code] = @User_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_UserInfo_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_UserInfo_DeleteByField]
GO
CREATE PROCEDURE [dbo].[TG_UserInfo_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[UserInfo] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_DocumentType_Insert]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_DocumentType_Insert]
GO
CREATE PROCEDURE [dbo].[TG_DocumentType_Insert]
	@DT_Code int output,
	@Type_Name varchar(50) = null ,
	@File_Extension varchar(50) = null ,
	@Is_Active bit = null ,
	@Creation_Date datetime = null ,
	@Updation_Date datetime = null 

AS

INSERT [dbo].[DocumentType]
(
	[Type_Name],
	[File_Extension],
	[Is_Active],
	[Creation_Date],
	[Updation_Date]

)
VALUES
(
	@Type_Name,
	@File_Extension,
	@Is_Active,
	@Creation_Date,
	@Updation_Date

)
	SELECT @DT_Code=SCOPE_IDENTITY();


GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_DocumentType_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_DocumentType_Update]
GO
CREATE PROCEDURE [dbo].[TG_DocumentType_Update]
	@DT_Code int,
	@Type_Name varchar(50) = null,
	@File_Extension varchar(50) = null,
	@Is_Active bit = null,
	@Creation_Date datetime = null,
	@Updation_Date datetime = null

AS

UPDATE [dbo].[DocumentType]
SET
	[Type_Name] = @Type_Name,
	[File_Extension] = @File_Extension,
	[Is_Active] = @Is_Active,
	[Creation_Date] = @Creation_Date,
	[Updation_Date] = @Updation_Date
 WHERE 
	[DT_Code] = @DT_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_DocumentType_SelectByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_DocumentType_SelectByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_DocumentType_SelectByPrimaryKey]
	@DT_Code int
AS

	SELECT 
		[DT_Code], [Type_Name], [File_Extension], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[DocumentType]
	WHERE 
			[DT_Code] = @DT_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_DocumentType_SelectAll]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_DocumentType_SelectAll]
GO
CREATE PROCEDURE [dbo].[TG_DocumentType_SelectAll]
AS

	SELECT 
		[DT_Code], [Type_Name], [File_Extension], [Is_Active], [Creation_Date], [Updation_Date]
	FROM [dbo].[DocumentType]

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_DocumentType_SelectByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_DocumentType_SelectByField]
GO
CREATE PROCEDURE [dbo].[TG_DocumentType_SelectByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'SELECT [DT_Code], [Type_Name], [File_Extension], [Is_Active], [Creation_Date], [Updation_Date] FROM [dbo].[DocumentType] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_DocumentType_DeleteByPrimaryKey]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_DocumentType_DeleteByPrimaryKey]
GO
CREATE PROCEDURE [dbo].[TG_DocumentType_DeleteByPrimaryKey]
	@DT_Code int
AS

DELETE FROM [dbo].[DocumentType]
 WHERE 
	[DT_Code] = @DT_Code

GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TG_DocumentType_DeleteByField]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[TG_DocumentType_DeleteByField]
GO
CREATE PROCEDURE [dbo].[TG_DocumentType_DeleteByField]
	@FieldName varchar(100),
	@Value varchar(1000)
AS

	DECLARE @query varchar(2000);

	SET @query = 'DELETE FROM [dbo].[DocumentType] WHERE [' + @FieldName  + '] = ''' + @Value + ''''
	EXEC(@query)

GO
